#include<bits/stdc++.h> 
using namespace std;
double A[1001];
double B[1001];
int main(){
	int k1, k2;
	cin>>k1;
	for(int i = 0;i<k1;i++){
		int n;
		double a;
		cin>>n>>a;
		A[n] = a;
	}
	cin>>k2;
	for(int i = 0;i<k2;i++){
		int n;
		double a;
		cin>>n>>a;
		B[n] = a;
	}
	int count = 0;

	string s = "";
	for(int i = 1000;i>=0;i--){
		// 至于为什么是20，反正得比10还要大就对了，毕竟要存储不知道多少位的系数和幂 
		char ss[20] = {0};
		if(A[i]!=0 && B[i]!=0){
			double sum = A[i] + B[i];
			// 和为0的情况也要忽略掉 
			if(sum != 0){
				sprintf(ss,"%d %.1f ",i,sum);
				s += ss;
				++count;
			}
		}
		else if(A[i]!=0){
			sprintf(ss,"%d %.1f ",i,A[i]);
			s += ss;
			++count;
		}
		else if(B[i]!=0){
			sprintf(ss,"%d %.1f ",i,B[i]);
			s += ss;
			++count;
		}	
	}
	// 这里反正就记个数，最多也就1000，所以ss[3]也行，不过反正空间充裕就随便写了 
	char ss[10] = {0};
	sprintf(ss,"%d",count);
	s = s.substr(0,s.length()-1);
	if(s==""){
		cout<<ss<<endl;
	}
	else{
		cout<<ss;
		cout<<" "<<s<<endl;
	}
    return 0;
}